import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home'
import login from "@/views/login/index.vue"
import goods from "@/views/goods/goods.vue"
import search from "@/views/search/search.vue"
import searchdetails from "@/views/searchdetail/searchdetail.vue"
import shopcart from "@/views/cart/shopcart.vue"
import zf from "@/views/zf/zf.vue"
const me =()=>import("@/views/me/me.vue")
import evaluate from "@/views/evaluate/evaluate.vue"



Vue.use(VueRouter)

const routes = [
  {
    path: '/home',
    name: 'Home',
    component: Home,
    meta: {showTop: true, showSearch: true}
  },
  {
    path: '/login',
    name: 'login',
    component: login
  },
  //商品详情
  {
    path:"/goods/:id",
    name:"goods",
    component:goods,
    meta: {showTop: true}
  },
  {
	  path: '/',
	  redirect: '/home'
	},
  {
    path:"/search/:id/:pageno",
    name:'search',
    component:search,
    meta: {showTop: true, showSearch: true}
  },
  {
    path:'/searchdetails',
    component:searchdetails,
    name:'searchdetails',
    meta: {showTop: true, showSearch: true}
  },
  {
    path:"/shopcart",
    component:shopcart,
    name:'shopcart',
    meta: {showTop: true}
  },
  {
    path:"/zf",
    component:zf,
    name:'zf',
  },
  {
    path:"/me",
    component:me,
    name:'me',
    redirect: '/me/info',
    children:[
      {path:"info",component:()=>import("@/views/me/meinfo.vue"),name:"meinfo"},
      {path:"updateinfo",component:()=>import("@/views/me/updateinfo.vue"),name:"updateinfo"},
      {path:"updatepwd",component:()=>import("@/views/me/updatepwd.vue"),name:"updatepwd"},
      {path:"/", redirect: '/me/info',}
   
   
    ]
  },
  {
    path:"/evaluate",
    component:evaluate,
    name:'evaluate',
    meta: {showTop: true
    }
  },
  {
    path:"/admin",
    component:()=>import('@/views/admin/admin.vue'),
    name:'admin',
  },
  {
    path:"/adminmain",
    component:()=>import('@/views/adminmain/adminmain.vue'),
   
    children:[
      {
        path:"info",
       component:()=>import('@/views/adminmain/info.vue'),name:"info",
      },
      {
        path:"admingosear",
        component:()=>import('@/views/adminmain/admingosear.vue'),name:"admingosear",
      },
      {
        path:"admingly",
        component:()=>import('@/views/adminmain/admingly.vue'),name:"admingly",
      },
      {
        path:"",component:()=>import('@/views/adminmain/info.vue'),
      },
      {path:'adminpl',component:()=>import('@/views/adminmain/adminpl.vue'),name:"adminpl"},
      {path:'update',component:()=>import('@/views/adminmain/adminupdate.vue'),name:"update"

      }
    ]

  }
 
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
router.beforeEach((to,from,next)=>{
  const topath=to.path;
  const frompath=from.path;
  if(topath==frompath){

  next(false)
  }else{
    next()
  }
  // router.onError(err=>{
  //   if(err instanceof navigationDuplicated){
  //     console.log('导航重复');
  //   }
  // })
 
})

export default router
